<html>
<head><title>Update Stats</title></head>
<?php

require 'config.php';

	$query = mysql_query("SELECT hostname, ip, username, hash, network from servers ORDER BY hostname");
        print "<table border=1>\n\t<th>Server Name</th><th>Number of Accounts</th>\n";
	while ($servers = mysql_fetch_row($query)) {
          if ($servers[0] == 'ivalue1' || $servers[0] == 'ivalue2') {
	    print "\t<tr><td><a href=listaccts.php?server=$servers[0]>" . $servers[0] . "</a></td>";
            mysql_query("DELETE FROM accounts where server = '$servers[0]'");
	    $version = showversion($servers[1],$servers[2],$servers[3],1);
	    mysql_query("UPDATE `servers` SET `whmVersion` = '${version}' WHERE `hostname` = '${servers[0]}'");
            $result = whmreq("/scripts/fetchcsv",$servers[1],$servers[2],$servers[3],1);
	    $accts = split("\n",$result);
	    print "<td>" . count($accts) . "</td></tr>\n";
	    foreach ($accts as $acct) {
                $data = split(",",$acct);
                list(,$domain,$ip,$account,,,,,,,,,$owner,,$skin,,$quota,,,,$package,,,,,,,,$created) = $data;
		
		// The array has an extra (empty) entry at the end.  Filter it out & don't add
		// it to the database.
		if ($domain != null) {
//		    $actualIP = "<a href=\"resolveallhosts.php\">Click to Resolve Hostnames</a>";
		    $sql = "INSERT INTO `accounts` (`server`,`account`,`domain`,`package`,`owner`,`realIP`,`skin`,`quota`,`dateCreated`,`actualIP`) VALUES ('$servers[0]','$account','$domain','$package','$owner','$ip','$skin','$quota','$created','$ip')";
		    mysql_query($sql);
		}
	    }
          }
	}
        print "</table>\n";
        mysql_close($dbh);
?>
</html>
